package com.huaxindata.im.main.chat.Helper;

import com.huaxindata.im.main.manager.ContactManager;
import com.huaxindata.im.model.contact.Contact;

import java.util.List;

/**
 * Created by Administrator on 2017/8/31.
 * 辅助进行消息发送人和接收人的帮助类
 */

public class ContactHelper {
    public static boolean isFriend(String id){
        if (id == null) {
            return false;
        }
        List<Contact> friendList = ContactManager.getFriendList();
        if (friendList==null||friendList.size()==0) {
            return false;
        }
        for (Contact friend : friendList) {
            boolean flag = friend.getClientId().equals(id);
            if (flag) {
                return true;
            }
        }
        return false;
    }
    public static boolean isGroup(String id){
        if (id == null) {
            return false;
        }
        List<Contact> groupList = ContactManager.getGroupList();
        if (groupList==null||groupList.size()==0) {
            return false;
        }
        for (Contact group : groupList) {
            boolean flag = group.getClientId().equals(id);
            if (flag) {
                return true;
            }
        }
        return false;
    }

    /**
     * 根据id获取一个联系人，不管是群还是好友
     * @return
     */
    public static Contact getContact(String id){
        if (id == null) {
            return null;
        }
        List<Contact> friendList = ContactManager.getFriendList();
        if (friendList!=null&&friendList.size()!=0) {
            for (Contact friend : friendList) {
                boolean flag = friend.getClientId().equals(id);
                if (flag) {
                    return friend;
                }
            }
        }
        List<Contact> groupList = ContactManager.getGroupList();
        if (groupList==null||groupList.size()==0) {
            return null;
        }
        for (Contact group : groupList) {
            boolean flag = group.getClientId().equals(id);
            if (flag) {
                return group;
            }
        }
        return null;
    }

    /**
     * 获取联系人，不管是同事还是好友
     * @param id
     * @return
     */
    public static Contact getContactFromFandC(String id){
        if (id == null) {
            return null;
        }
        List<Contact> friendList = ContactManager.getFriendList();
        if (friendList!=null&&friendList.size()!=0) {
            for (Contact friend : friendList) {
                boolean flag = friend.getClientId().equals(id);
                if (flag) {
                    return friend;
                }
            }
        }
        List<Contact> colleagueList = ContactManager.getColleagueList();
        if (colleagueList==null||colleagueList.size()==0) {
            return null;
        }
        for (Contact colleague : colleagueList) {
            boolean flag = colleague.getClientId().equals(id);
            if (flag) {
                return colleague;
            }
        }
        return null;
    }
}
